package com.mark.anto.bootstrap;

import com.mark.anto.service.CalculateService;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.util.Assert;

/**
 * @Description: Spring条件装配 基于注解方式
 * @Author: Mark
 * @CreateDate: 2019/9/1 9:11
 * @Version: 3.00.001
 * @Copyright : 豆浆油条个人非正式工作室
 *
 * @see CalculateService
 */
@ComponentScan(basePackages = "com.mark.anto.service")
public class ConditionByProfileAnnoBootstrap {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = new SpringApplicationBuilder(ConditionByProfileAnnoBootstrap.class)
                .web(WebApplicationType.NONE)
                .profiles(CalculateService.JAVA8_PROFILE_VALUE)
                .run(args);

        //从上下文中获取Bean
        CalculateService calculateService = context.getBean(CalculateService.class);
        Assert.notNull(calculateService, "获取到Bean为为空！");
        Integer sum = calculateService.sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        System.out.println("calculateService.sum(1...10) 的计算结果:"+sum);

        //关闭上下文
        context.close();
    }

}
